home *** CD-ROM | disk | FTP | other *** search
- Path: keats.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Getting date in UNIX
- Date: 21 Mar 1996 09:27:56 -0800
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4is3isINNhdf@keats.ugrad.cs.ubc.ca>
- References: <4ik447$bn7@raffles.technet.sg> <4ike32$c8n@ccshst05.cs.uoguelph.ca>
- NNTP-Posting-Host: keats.ugrad.cs.ubc.ca
-
- In article <4ike32$c8n@ccshst05.cs.uoguelph.ca>,
- Toby K Hay <thay@uoguelph.ca> wrote:
- >Leonard Sim (leonard@pacific.net.sg) wrote:
- >: Can anyone please inform me how to obtain the date in UNIX C??
- >: I just need the date in this format "dd/mm/yyyy". Thanks!!!
- >
- >I just did this for the first time using an example from my Turbo C
- >reference by Herb Schildt. (Will mentioning that name start another
- >long thread on his failings?)
- >
- >#include "time.h"
- >#include "stdio.h"
- >int main(void)
- >{ struct tm *ptr;
- > time_t lt;
- >
- > lt = time(NULL);
- > ptr = localtime(<);
- > printf(asctime(ptr));
-
- Is using printf() for a simple string without formatted conversion Schildt's
- idea or did you come up with it yourself? :)
-
- On some systems, I can still get the C Shell to mess up _today_ because it uses
- printf() to print messages that should be done with puts().
-
- For instance, if you type !%s%s%s%s%s%s%s%s in the C shell, you will get some
- amusing results as it tries to say that it can't find the "%s%s%s..." in your
- history. Of course, it echoes that using printf(), which treats the procession
- of %s's as conversion specifiers for which no matching arguments exist.
-
- Not that I would expect asctime() to generate a % anywhere, but still...
-
- Read the documentation on strftime(). That is the proper way to get the date
- into whatever format you want, which is what was asked for. The asctime()
- function gives you a the time and date in a predetermined format, not in
- "dd/mm/yyyy". It's no good answering the wrong question.
-
- By the way, the above can be re-written as ``puts(ctime(<));''.
-
- > return 0;
- >}
- --
-
-